/**fd in parent and child process*/
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>

int main(int argc,char ** argv)
{
	int ret;
	int fd;
	fd=open("test.txt",O_WRONLY | O_TRUNC);
	if(-1==fd){
		perror("open error");
		return 1;
	}
	switch(fork()){
		case -1:
			perror("fork error");
			return 1;
		case 0:
			printf("i am child process\n");
			write(fd,"hello world",11);
			close(fd);
			return 0;
		default:
			printf("i am parent process\n");
			write(fd,"123456",6);
			close(fd);
			return 0;
	}
}
